﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Yeex.Boss.Web.Helper
{
    public static class JuiHelper
    {
        private static Dictionary<string, string> _Type_SQLServer_JUI;
        private static string[] _StringType_SQLServer = { "char", "varchar", "nchar", "nvarchar", "text", "ntext" };

        static JuiHelper()
        {
            Init();
        }

        private static void Init()
        {
            _Type_SQLServer_JUI = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) { 
                {"float", "number"},
                {"decimal", "number"},
                {"numeric", "number"},
                {"tinyint", "digits"},
                {"smallint", "digits"},
                {"int", "digits"},
                {"bigint", "digits"},
                {"time", "date"},
                {"date", "date"},
                {"datetime", "date"},
                {"datetime2", "date"}
            };
        }

        public static string SqlServerToJui(string typeName)
        {
            if (string.IsNullOrEmpty(typeName))
            {
                return string.Empty;
            }

            typeName = typeName.ToLower();
            if (_Type_SQLServer_JUI.ContainsKey(typeName))
            {
                return _Type_SQLServer_JUI[typeName];
            }

            return string.Empty;
        }

        public static bool IsSqlServerStringType(string dataType)
        {
            if (string.IsNullOrEmpty(dataType))
            {
                return true;
            }

            return _StringType_SQLServer.Contains(dataType.ToLower());
        }
    }
}